# -*- coding:utf-8 -*-
from concurrent import futures
from urllib.parse import urlencode

from keywords import *
from cmsRequestZhuCe import run
from concurrent.futures import ThreadPoolExecutor

def readtxt():  #返回username
    wordlist = []
    for line in open("username.txt", encoding='utf-8'):
        wordlist.append(line.strip())
    # print(wordlist)
    return wordlist[0]
def writenumtxt(msg):
    # print(request.META)
    print(msg)
    try:
        with open('postnum.txt', 'w+', encoding='utf-8') as f:
            f.write(msg + '\n')
    except:
        print('cuow')
        pass

def readnumtxt():
    # print(request.META)
    wordlist = []
    try:
        for line in open("postnum.txt", encoding='utf-8'):
            wordlist.append(line.strip())
        return wordlist[0]
    except:
        print('cuow')
        pass

def writelogtxt(msg):
    # print(request.META)
    print(msg)
    try:
        with open('log.txt', 'a+', encoding='utf-8') as f:
            f.write(msg + '\n')
    except:
        print('cuow')
        pass
def getweixin():  #返回username
    wordlist = []
    for line in open("weixin.txt", encoding='utf-8'):
        wordlist.append(line.strip())
    # print(wordlist)
    return wordlist[0]

def dorun(host):
    readusername = readtxt()
    password = 'xiaogege123'
    startnum = readnumtxt()
    for i in range(int(startnum), 10000):
        username = readusername
        name = f'{username}{i}'
        email = f'{username}{i}@163.com'
        writenumtxt(str(i + 1))
        # print(name)
        # print(email)
        # print(password)
        # print(getKeywords())
        title = f'{getKeywords()}{getBackwords()} {getKeywords()}{getBackwords()} {getKeywords()}{getBackwords()} '
        print('题目是' + title)
        content = f'[在评论里边看到在这里领券] 领券微信请加--{getweixin()}    微信加好友{getweixin()}' \
                  f'加{getweixin()}可以看免费vip电影，可以领隐藏优惠券，请认准微信{getweixin()}' \
                  f'----------------------------------------------------------------------' \
                  f'----------------------------------------------------------------------' \
                  f'其实就是大家听说的淘宝内部优惠券了，{getKeywords()} ?只是可惜的是大局部人都不晓得去哪里找这个优惠券。' \
                  f'{getKeywords()}领券超快，享用飞速的觉得，让你领券开心省不停！淘宝天猫大额半价优惠券是怎么回事？很多宝宝们都会剁手，过后很伤心！殊不知其实有很多的优惠可以领！我们这里可以快速查询全网的优惠，只要有优惠通通都能查出来！' \
                  f'{getKeywords()}享受飞速的感觉，让你领券开心省不停！在领券页面里 不仅仅能查优惠 还有超值的大额优惠，更有超多的惊喜等着你，让你花最少的钱买到最多的东西！' \
                  f'{getKeywords()}{getBackwords()} {getKeywords()}{getBackwords()}' \
                  f'{getlinkwords()}   {getlinkwords()}'
        # print(content)
        userinfo = f'{getKeywords()}{getBackwords()} {getKeywords()}{getBackwords()} {getKeywords()}{getBackwords()} '

        writelogtxt(f'for循环是--{i}---用户名是--{name}----密码是{password}---email是{email}')
        run(host, name, password, email, title, content, userinfo)

if __name__ == '__main__':
    # hostlist = ['www.farpop.com','www.qixiqi.com']
    hostlist = ['www.nbaxx.com']
    with futures.ProcessPoolExecutor(max_workers=2) as executor:  # 多线程
        dict = {}
        for i in hostlist:
            fun = executor.submit(dorun, i)
            dict[fun] = i
            print(dict)

